<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
	function shuff(source)
	{
	
	    var goal=[];
	    for(var i=0;i<source.length;i++)
	    {
	        var pos=Math.floor(Math.random()*(source.length-i));
	        goal[i]=source[pos];
	        source[pos]=source[source.length-1-i];
	    }
	    return goal;
	} 

	$(function() {
		$("input[type='submit']").bind("click",function(event) {
			var points = $("textarea").val().split('\n');
			points.length = points.length - 1;
			var randomPoints = shuff(points);
			var persons = $("input[type='text']").filter(function() {return $(this).val() != ""});
			var personCount = persons.length;
			var pointCount = randomPoints.length;
			var personPointCount = Math.floor(pointCount / personCount); 
			var person = [];
			for(var j = 0; j < personPointCount * personCount; j++){
			    person[j] = randomPoints.slice(j*personPointCount, (j + 1) * personPointCount);
			}

 			var restPoints = randomPoints.slice(personPointCount * personCount, randomPoints.length);
 			for(var j = 0; j < restPoints.length; j++) {
				person[j].push(restPoints[j]);
			}
 			
 			$("div").text("");
			for(var j = 0; j < person.length; j++) {
				$("div").append("<b>" + persons[j].value + ":</b>" + person[j].join('\n') + "<br />");
			}

		});
	});
</script>
</head>
<body>
	<h1>速递易重庆网点</h1>
	<textarea rows="10" cols="100"></textarea>
	<h1>人员</h1>
	<input type="text" name="p1" />
	<input type="text" name="p2" />
	<input type="text" name="p3" />
	<input type="text" name="p4" />
	<br>
	<br>
	<input type="submit" value="计算" style="width: 200px; height: 40px;"/>
	<br>
	<br>
	<div style="font-size: 14px; line-height: 28px;"></div>
</body>
</html>